package com.ls.blog.controller;

import static com.ls.blog.common.consts.Methods.*;

import com.ls.blog.common.valid.Delete;
import com.ls.blog.dto.RoleDTO;
import com.ls.blog.service.RoleService;
import com.ls.blog.utils.R;
import com.ls.blog.utils.Result;
import com.ls.blog.vo.RoleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lishun
 * @since 2022-01-14
 */
@RestController
@RequestMapping("/role")
@Api(tags = "角色模块")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @GetMapping("/admin/listOpt")
    @ApiOperation(value = "后台角色选项",httpMethod = GET)
    public Result<List<RoleDTO>> listOpt(){
        return R.ok(roleService.listOpt());
    }

    @GetMapping("/admin/list")
    @ApiOperation(value = "后台角色列表",httpMethod = GET)
    public Result<List<RoleDTO>> roleDTOList(){
        return R.ok(roleService.roleDTOList());
    }

    @PutMapping("/admin/edit")
    @ApiOperation(value = "后台修改角色",httpMethod = PUT)
    public Result<?> editRole(@RequestBody RoleVO roleVO){
        roleService.editRole(roleVO);
        return R.ok();
    }

    @GetMapping("/admin/getRoleById")
    @ApiOperation(value = "后台根据角色id查找角色",httpMethod = GET)
    public Result<RoleDTO> getRoleById(Integer id){
        return R.ok(roleService.getRoleById(id));
    }

    @PostMapping("/admin/add")
    @ApiOperation(value = "后台根据角色id查找角色",httpMethod = POST)
    public Result<?> addRole(@RequestBody RoleVO roleVO){
        roleService.addRole(roleVO);
        return R.ok();
    }

    @DeleteMapping("/admin/delete/{id}")
    @ApiOperation(value = "后台删除角色列表",httpMethod = DELETE)
    public Result<?> deleteRole(@PathVariable Integer id){
        roleService.deleteRole(id);
        return R.ok();
    }

}
